package edu.uc.ui.ctrl25;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public abstract class BaseAction extends ActionSupport{
	private static final long serialVersionUID = 1L;
	
	private final String AREANAME_KEY = "areaName";
	protected String areaName = "area25";
	
	protected java.util.Map<String, Object> request;
	protected java.util.Map<String, Object> session;
	protected java.util.Map<String, Object> application;
	
	protected String pageNum;
	protected String pageSize;
	protected String requestURI;
	protected String queryString;
	@SuppressWarnings("unchecked")
	public BaseAction() {
		if(ActionContext.getContext().getSession().get(AREANAME_KEY) == null) {
			ActionContext.getContext().getSession().put(AREANAME_KEY, areaName);
		}
		request = (java.util.Map<String,Object>)ActionContext.getContext().get("request");
		session = ActionContext.getContext().getSession();
		application = ActionContext.getContext().getApplication();
		requestURI = ServletActionContext.getRequest().getRequestURI();
		queryString = ServletActionContext.getRequest().getQueryString();
	}
	
	/**
	 * 操作类型：用于获取url中的oper参数
	 */
	protected String oper;
	
	public String getOper() {
		return oper;
	}
	
	public void setOper(String oper) {
		this.oper = oper;
	}
	
	/**
	 * 检测是否登录，未登录，则返回login；否则，返回view
	 * @return
	 */
	public String checkLogin() {
		System.out.println("checkLogin()");
		if(ActionContext.getContext().getSession().get("loginuser") == null) {
			return "login";
		}
		return "view";
	}
	
	/**
	 * 清空登录信息：清空会话的所有数据
	 */
	public void clearLogin() {
		ActionContext.getContext().getSession().clear();
	}
	
	public String checkRight() {
		System.out.println("checkRight");
		if(ActionContext.getContext().getSession().get("loginuser") == null) {
			System.out.println("checkLogin:no");
			return "login";
		}
		if(ActionContext.getContext().getSession().get("isadmin") == null) {
			System.out.println("checkRight:no");
			return "go_noright";
		}
		return "";
	}
	
	public String getPageNum() {
		return pageNum;
	}
	
	public void setPageNum(String pageNum) {
		this.pageNum = pageNum;
	}
	
	public String getPageSize() {
		return pageSize;
	}
	
	public void setPageSize(String pageSize) {
		this.pageSize = pageSize;
	}
	
	
	
}
